#!usr/bin/env python
#Creates files with random fasta sequences

import sys
import random
import numpy

def split_fasta(line):
	'''Takes a string and inserts an end of line characther at after each 60 charachters'''
	line2=''
	while(len(line)>60):
		line2=line2+line[0:60]
		line2=line2+'\n'
		line=line[60:]
	line2=line2+line
	return(line2)


alphabet=['A','R','B','D','C','E','Q','H','I','L','K','M','F','P','S','T','W','Y','V','-']

#n_protein=sys.argv[1] #16
#length=sys.argv[2] #150
#file_name=sys.argv[3]
#n_files=sys.argv[4]
n_protein=16
length=150
file_name='random_fasta_'
n_files=100

for count in range(1,n_files+1):
	print 'Working on '+str(count)
	file_out=file_name+str(count)+'.msl'
	seq_list=[]
	for i in range(n_protein):
		seq=[]
		for j in range(length):
			r=random.uniform(0,len(alphabet)-1)
			r=int(numpy.round(r,0))
			seq.append(alphabet[r])
		seq_list.append(split_fasta(''.join(seq)))

	handle=open(file_out,'w')
	for i in range(len(seq_list)):
		handle.write('>sp'+str(i+1)+'\n')
		handle.write(seq_list[i]+'\n')
	handle.close()
